var app = getApp()
Page({
  data: {
    mymoney: 0,
    myfans: 0,
     pageIndex: 1,
    pageSize: 10000000,
    hide: false,
  },
  bindProfit: function () {
    /*
    wx.navigateTo({
      url:'profitlist',
    })
    */
  },
  gotomymoney: function () {
    wx.navigateTo({
      url:'mymoney',
    })
  },
  gotowithdrawhistory: function () {
    wx.navigateTo({
      url: 'withdrawhistory',
    })
  },

  
  onbindRep: function () {
    wx.redirectTo({
      url: 'share',
    })
  },
  oncatchconfirm: function () {
    this.setData({
      hide: false,
    })
  },
  onbindDeposit: function () {

    wx.redirectTo({
      url: 'deposit',
    })

  },
  gotomyfans: function (e) {
    wx.redirectTo({
      url: 'myfans'
    })
  }, 
  getmyfans: function () {
    var that = this;
    var myfans = that.data.myfans;
    var service = 'User.getInvitationList';
    var pageIndex = that.data.pageIndex;
    var pageSize = that.data.pageSize;
    var leveId = 1;   

    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, leveId: leveId, pageIndex: pageIndex, pageSize: pageSize },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        if (!res.data.data.code) {
          myfans += parseInt( res.data.data.list.total);
          that.setData({ myfans: myfans })
        }
      }
    })
    var leveId = 2;
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId, leveId: leveId, pageIndex: pageIndex, pageSize: pageSize },
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        if (!res.data.data.code) {
          myfans += parseInt(res.data.data.list.total);
          that.setData({ myfans: myfans })
        }
      }
    })

    var service = 'Wechat.getUserInfo';
    wx.request({
      method: 'POST',
      url: app.globalData.APIURL,
      data: { service: service, openId: app.globalData.openId},
      header: { 'Content-Type': 'application/x-www-form-urlencoded' },
      success: function (res) {
        if (!res.data.data.code) {
          var mymoney = parseInt(res.data.data.info.cashBalance);
          that.setData({ mymoney: mymoney })
        }
      }
    })

    
  },
  onLoad: function (options) {
    var that = this;
    if (options.fromInviteCode) {
      app.globalData.fromInviteCode = options.fromInviteCode;
    }
    app.appstart();
    that.getmyfans();
  }
})